<template>
	<view class="content">
		<image class="logo" src="/static/logo.jpg"></image>
		<view class="text-area">
			<text class="title">公众号：{{title}}</text>
		</view>
		
		<view style="margin-top: 30px;">
			<uni-forms :modelValue="tickInfo" ref="formRef" label-align="left" :label-width="350"
				label-position="top" style="padding: 0px 16px;">
				<uni-forms-item label="手机号码" name="phone" required>
					<uni-easyinput type="number" v-model="tickInfo.phone" placeholder="请填写手机号码" />
				</uni-forms-item>
				
				<uni-forms-item label="场次" name="sessionName" required>
					<uni-easyinput type="text" v-model="tickInfo.sessionName" placeholder="请填写场次名称" trim="all"
						suffix-icon="contact" />
				</uni-forms-item>
				
				<uni-forms-item label="票档" name="gradeName" required>
					<uni-easyinput type="text" v-model="tickInfo.gradeName" placeholder="请填写票档名称" trim="all" />
				</uni-forms-item>
				
				<view style="margin-top: 20px;">
					<button type="primary" @click="onSendSms">发送短信</button>
				</view>
			</uni-forms>
		</view>
		
		<view style="margin-top: 50px">
			<button type="primary" @click="onJumpHome">回到首页</button>
		</view>
	</view>
</template>

<script lang="ts" setup>
	import { ref } from "vue";
	import { onLoad } from "@dcloudio/uni-app";
	
	const title = getApp().globalData.appName;
	let tickInfo = ref({
		phone: "18011873976",
		sessionName: "2024-11-17 周日 15:30",
		gradeName: "100.0元"
	});
	const formRef = ref()
	
	const sxf_theater = uniCloud.importObject("sxf-theater");
	
	onLoad(async(option) => {
		console.log("option", option);
	});
	
	const onSendSms = async () => {
		formRef.value.validate().then(async (formRes) => {
			if (tickInfo.value.phone.length === 0) {
				uni.showToast({
					title:"请填写手机号码"
				});
				return;
			} else if (tickInfo.value.sessionName.length === 0) {
				uni.showToast({
					title:"请填写场次"
				});
				return;
			} else if (tickInfo.value.gradeName.length === 0) {
				uni.showToast({
					title:"请填写票档"
				});
				return;
			}
			
			let res = await sxf_theater.sendTestOrderSms(tickInfo.value);
			console.log("res：", res);
		});
	};
	
	const onJumpHome = () => {
		// 进入首页
		uni.redirectTo({
			url: "/pages/ticker/list"
		});
	};
</script>

<style lang="scss" scoped>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 30rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 20rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>
